//
//  LNUniversalHeader.h
//  LNUniversal
//
//  Created by liu nian on 15/5/25.
//  Copyright (c) 2015年 Liu Nian site:http://iliunian.com. All rights reserved.
//

#ifndef LNUniversal_LNUniversalHeader_h
#define LNUniversal_LNUniversalHeader_h

#if DEBUG
#define NLog(xx, ...)  NSLog(@"%s(%d): " xx, __PRETTY_FUNCTION__, __LINE__, ##__VA_ARGS__)
#else
#define NLog(xx, ...)  ((void)0)
#endif

//未实现虚函数 抛出异常
#define RaiseException() [NSException raise:@"需要实现该函数" format:@"你需要实现%@类的%@函数", NSStringFromClass([self class]), NSStringFromSelector(_cmd)]
//格式化输出
#define _StrFromFloat(F)     [NSString stringWithFormat: @"%f", F]
#define _StrFromInt(I)       [NSString stringWithFormat: @"%d", I]

#define _NumFromBOOL(B)      [NSNumber numberWithBool: B]
#define _NumFromInt(I)       [NSNumber numberWithInt: I]
#define _NumFromDouble(D)    [NSNumber numberWithDouble: D]

#define _FormatStr(fmt, ...) [NSString stringWithFormat:fmt, ##__VA_ARGS__]


//----------------------系统设备相关----------------------------
//获取设备屏幕尺寸
#define SCREEN_WIDTH ([UIScreen mainScreen].bounds.size.width)
#define SCREEN_HEIGHT ([UIScreen mainScreen].bounds.size.height)//应用尺寸
#define APP_WIDTH [[UIScreen mainScreen]applicationFrame].size.width
#define APP_HEIGHT [[UIScreen mainScreen]applicationFrame].size.height
//获取系统版本
#define IOS_VERSION [[[UIDevice currentDevice] systemVersion] floatValue]
#define CurrentSystemVersion [[UIDevice currentDevice] systemVersion]
#define isIOS4 ([[[UIDevice currentDevice] systemVersion] intValue]==4)
#define isIOS5 ([[[UIDevice currentDevice] systemVersion] intValue]==5)
#define isIOS6 ([[[UIDevice currentDevice] systemVersion] intValue]==6)
#define isIOS7 ([[[UIDevice currentDevice] systemVersion] intValue]==7)
#define isIOS8 ([[[UIDevice currentDevice] systemVersion] intValue]==8)
#define isAfterIOS4 ([[[UIDevice currentDevice] systemVersion] intValue]>=4)
#define isAfterIOS5 ([[[UIDevice currentDevice] systemVersion] intValue]>=5)
#define isAfterIOS6 ([[[UIDevice currentDevice] systemVersion] intValue]>=6)
#define isAfterIOS7 ([[[UIDevice currentDevice] systemVersion] intValue]>=7)
#define isAfterIOS8 ([[[UIDevice currentDevice] systemVersion] intValue]>=8)
//获取当前语言
#define CurrentLanguage ([[NSLocale preferredLanguages] objectAtIndex:0])

//判断是否 Retina屏、设备是否%fhone 5、是否是iPad
#define isPad (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad)

//判断是真机还是模拟器
#if TARGET_OS_IPHONE
//iPhone Device
#endif
#if TARGET_IPHONE_SIMULATOR
//iPhone Simulator
#endif
//----------------------内存相关----------------------------
//使用ARC和不使用ARC
#if __has_feature(objc_arc)
//compiling with ARC
#else
// compiling without ARC
#endif

//----------------------图片----------------------------

//读取本地图片
#define LOADIMAGE(file,ext) [UIImage imageWithContentsOfFile:[[NSBundle mainBundle]pathForResource:file ofType:ext]]

//定义UIImage对象
#define ImageNamed(A) [UIImage imageNamed:A]

//去除遮光效果
#define ImageRenderingMode(A)   [[UIImage imageNamed:A] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal]

//----------------------颜色类---------------------------

// rgb颜色转换（16进制->10进制）
#define COLOR_HEX(rgbValue) [UIColor colorWithRed:((float)((rgbValue & 0xFF0000) >> 16))/255.0 \
green:((float)((rgbValue & 0xFF00) >> 8))/255.0    \
blue:((float)(rgbValue & 0xFF))/255.0             \
alpha:1.0]

// 随机颜色
#define COLOR_RANDOM = [UIColor colorWithRed:(arc4random() % 255)/255.0 \
green:(arc4random() % 255)/255.0 \
blue:(arc4random() % 255)/255.0 \
alpha:(arc4random() % 255)/255.0]

//带有RGBA的颜色设置
#define COLOR_RGBA(R, G, B, A) [UIColor colorWithRed:R/255.0 green:G/255.0 blue:B/255.0 alpha:A]

//清除背景色
#define COLOR_CLEAR [UIColor clearColor]

//----------------------其他----------------------------
//定义字号
#define FONT_TITLE(X)                   [UIFont systemFontOfSize:X]
#define BOLDFONT_TITLE(X)               [UIFont boldSystemFontOfSize:X]

#define STRSIZE(__str__, __fontsize__)\
[__str__ sizeWithAttributes:@{NSFontAttributeName:FONT_TITLE(__fontsize__)}]
//方正黑体简体字体定义
#define FONT(F) [UIFont fontWithName:@"FZHTJW--GB1-0" size:F]
#define kFontSTHeitiSC_Light(X)   [UIFont fontWithName:@"STHeitiSC-Light" size:X]
#define kFontSTHeitiSC_Medium(X) [UIFont fontWithName:@"STHeitiSC-Medium" size:X]
//设置View的tag属性
#define VIEWWITHTAG(_OBJECT, _TAG)    [_OBJECT viewWithTag : _TAG]
//程序的本地化,引用国际化的文件
#define MyLocal(x, ...) NSLocalizedString(x, nil)

//G－C－D
#define GCDBACK(block) dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), block)
#define GCDMAIN(block) dispatch_async(dispatch_get_main_queue(),block)

//NSUserDefaults 实例化
#define USER_DEFAULT [NSUserDefaults standardUserDefaults]

//由角度获取弧度 由弧度获取角度
#define degreesToRadian(degrees) (M_PI * (degrees) / 180.0)
#define radianToDegrees(radian) (radian*180.0)/(M_PI)

//Alert
#define SHOWALERT(title, msg, cancel) do{ \
UIAlertView *alertview = [[UIAlertView alloc] initWithTitle:title message:msg delegate:nil cancelButtonTitle:cancel otherButtonTitles:nil, nil]; \
[alertview show]; }while(0)

//Instance
#define SingletonInterface(Class) \
+ (Class *)sharedInstance;

#define SingletonImplementation(Class) \
static Class *__ ## sharedSingleton; \
\
\
+ (void)initialize \
{ \
static BOOL initialized = NO; \
if(!initialized) \
{ \
initialized = YES; \
__ ## sharedSingleton = [[Class alloc] init]; \
} \
} \
\
\
+ (Class *)sharedInstance \
{ \
return __ ## sharedSingleton; \
} \
\

#endif
